package com.edais.actions;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.edais.domain.Bank;
import com.edais.service.BankService;
import com.edais.util.CommonUtil;
import com.edais.util.Consts;
import com.edais.util.JsonUtil;
import com.edais.util.Message;

@Controller
@RequestMapping("/bank")

public class BankAction implements Serializable {

	private static final Log logger = LogFactory.getLog(BankAction.class);

	@Autowired
	private BankService bankService;

	@RequestMapping(value = "/queryAllBankInfo")
	public void getUserBankCardInfo(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);

		try {
			Map<String, Object> requestMap = new HashMap<String, Object>();
			List<Bank> bankList = this.bankService.queryAllBankInfo(requestMap);

			jsonMap.put("bankList", bankList);

			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		} catch (Exception e) {
			logger.error("userCard/getUserBankCardInfo 异常:" + e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}
	}
	
	/**
	 * 查询银行信息列表
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryBankList")
	public void queryBankList(HttpServletRequest request, HttpServletResponse response){
		
		Map<String, Object> jsonMap;
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);

		try{
			jsonMap = this.bankService.queryBankList(paramsMap);
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch(Exception e){
			logger.error("/bank/queryBankList异常-----" + e.getMessage());
			
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
								Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
								Message.CnDescriptionExpression.BUSINESSE_ERROR);
			// 处理返回结果
			CommonUtil.responseJson(result, response);
		}
	}


	/**
	 * 查询路由银行信息列表
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryRouteBankList")
	public void queryRouteBankList(HttpServletRequest request, HttpServletResponse response){

		Map<String, Object> jsonMap;
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);

		try{
			jsonMap = this.bankService.queryRouteBankList(paramsMap);
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch(Exception e){
			logger.error("/bank/queryRouteBankList异常-----" + e.getMessage());

			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
					Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			// 处理返回结果
			CommonUtil.responseJson(result, response);
		}
	}
}
